#include<cstdio>
int a[21],d[21];
bool f[52500];
int main()
{
	freopen("test.in","r",stdin);
	for(int i=2;i<=n;)
	int n;
	while(scanf("%d",&n),n!=0)
	{
		int p=0;
		for(int i=1;i<=n;i++)
		{
			int t;
			scanf("%d",&t);
			p+=d[t];
